﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Studio.Foundation.Ontologies;
using System.Xml.Schema;
using System.Xml;
using System.IO;
using System.Reflection;

namespace Studio.Resource.Assemblies
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string schemaString = this.textBox1.Text;
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(schemaString);
            XmlReader reader = new XmlTextReader(new StringReader(doc.OuterXml));

            // Read the xsd
            XmlSchemaSet schemaSet = new XmlSchemaSet();
            XmlSchema xsd = schemaSet.Add(null, reader);
            schemaSet.Compile();

            XsdConverter converter = new XsdConverter(null, null, null);
            Assembly assembly = converter.XsdToAssembly(xsd);
            Type[] types = assembly.GetTypes();
            if (types.Count() < 1)
            {
                return;
            }

            Type type = types[0];
            PropertyInfo[] props = type.GetProperties();
            foreach (PropertyInfo prop in props)
            {
                System.Diagnostics.Debug.WriteLine(prop.Name);
                System.Diagnostics.Debug.WriteLine(prop.PropertyType);
            }
        }
    }
}
